package com.problem.leetcode;

import org.openjdk.jmh.annotations.*;

import java.util.concurrent.TimeUnit;

/**
 * 解题思路:进制转换
 *
 * @author didi
 * @DESCRIPTION
 * @create 2019-05-29 13:46
 **/
@State(Scope.Thread)
@BenchmarkMode({Mode.Throughput})
@Warmup(iterations = 3, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 5, timeUnit = TimeUnit.MICROSECONDS)
@Threads(16)
@Fork(4)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class Problem171 {



    public int titleToNumber(String s) {

        int sum = 0;
        int base = 1;
        for (int index = s.length() - 1; index >= 0; --index) {
            int value = s.charAt(index) - 64;

            if (s.length() - 1 - index > 0) {
                base  = base * 26;
            }

            sum += value * base;
        }
        return sum;
    }

    @Benchmark
    public void testVoid() {
        String s = "ZYKJHJKHJKHJKHUIOYIUASDNBVBNCVHFGHRYTRASD";
        titleToNumber(s);
    }


}
